package com.appspot.etao.model;

import javax.jdo.annotations.EmbeddedOnly;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.appspot.etao.util.StringUtil;
import com.taobao.top.domain.Location;

@PersistenceCapable
@EmbeddedOnly
public class LocationModel extends BaseModel {
	private static final long serialVersionUID = 2189426537410054238L;
	
//    @PrimaryKey
//    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;
    
    /** 邮政编码 */
    @Persistent
	private String zip;
    
    /** 详细地址 */
	@Persistent
	private String address;
    
	/** 所在城市 */
    @Persistent
	private String city;
    
    /** 所在省份 */
    @Persistent
	private String state;
    
    /** 国家名称 */
    @Persistent
	private String country;
    
    /** 区/县 */
    @Persistent
	private String district;

	private Location location;

	public LocationModel() {
		
	}
	
	public LocationModel(Location location) {
		setLocation(location);
	}
	
	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getDistrict() {
		return district;
	}

	public void setDistrict(String district) {
		this.district = district;
	}

    public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
		
		this.zip = StringUtil.cut(location.getZip());
		this.address = StringUtil.cut(location.getAddress());
		this.city = StringUtil.cut(location.getCity());
		this.state = StringUtil.cut(location.getState());
		this.country = StringUtil.cut(location.getCountry());
		this.district = StringUtil.cut(location.getDistrict());
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer("");
		sb.append("[");
		sb.append(zip);
		sb.append(",");
		sb.append(address);
		sb.append(",");
		sb.append(city);
		sb.append(",");
		sb.append(state);
		sb.append(",");
		sb.append(country);
		sb.append(",");
		sb.append(district);
		sb.append("]");

		return sb.toString();

	}
}
